package com.qf.listener;

import com.qf.constant.RabbitMQConstants;
import com.qf.model.StandardSubmit;
import com.qf.service.FilterChainManager;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author dell
 * @version V1.0
 * @Date 2022/6/6 15:25:52
 */
@Component
public class PreSendQueueListener {

    /**
     * 责任链管理
     */
    @Autowired
    private FilterChainManager filterChainManager;


    /**
     * 监听  借口模块微服务 发送过来的客服表单
     */
    //@RabbitListener(queues = RabbitMQConstants.TOPIC_PRE_SEND)

    /**
     * 使用注解创建队列  创建交换机 绑定routingKey  再监听队列
     * @param message
     * @param channel
     * @param standardSubmit
     * @throws Exception
     */
    @RabbitListener(bindings = {
            @QueueBinding(
                    value = @Queue(value = RabbitMQConstants.TOPIC_PRE_SEND,
                            durable = "true",autoDelete = "false"),
                    exchange = @Exchange(value = RabbitMQConstants.TOPIC_PRE_SEND+"_exchange"),
                    key = {"#"}
            )
    })
    public void  consume(Message message, Channel channel, StandardSubmit standardSubmit) throws Exception {
        //执行过滤器
        // 执行大量的策略链
        filterChainManager.executeFilter(standardSubmit);

        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }
}
